package com.base.controller.hwn;

import com.base.api.bms.IMipsSettlementUploadService;
import com.base.api.emr.IHisCaseRecordService;
import com.base.api.hwn.LogService;
import com.base.api.thbi.InsuranceService;
import com.base.utils.ResultUtil;
import com.base.utils.ThreadLocalUtil;
import com.base.vo.bms.MipsSettlementUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping(value = "/hwn", produces = "application/json;charset=UTF-8")
public class HwnController {

    @Autowired
    private LogService logService;
    @Autowired
    private InsuranceService insuranceService;
    @Autowired
    private IMipsSettlementUploadService mipsSettlementUploadImpl;
    @Autowired
    private IHisCaseRecordService hisCaseRecordService;

    @PostMapping(value= "/queryUnilateral")
    public String queryUnilateral(String str,String startDate,String endDate,String yblx)  {
        return logService.queryUnilateral(str,startDate,endDate,yblx);
    }

    @PostMapping(value= "/downLoadInusrancevsprice")
    public String downLoadInusrancevsprice(String startDate,String yblx) throws IOException {
        return insuranceService.updateInsuranceSychi(yblx,startDate);
    }

    @PostMapping(value= "/findInsuranceVsPrice")
    public String findInsuranceVsPrice(String yblx,String itemCode,String itemName,String page , String limit,String order,String no)  {
        return insuranceService.findAll(yblx,itemCode,itemName,page,limit,order,no);
    }

    @PostMapping(value= "/findInsuranceVsPriceUpdateLog")
    public String findInsuranceVsPriceUpdateLog(String yblx)  {
        return insuranceService.findUpdateLog(yblx);
    }

    @PostMapping(value= "/findMipsSettleMentUploadDetail")
    public String findMipsSettleMentUploadDetail(String yblx,String patientId, String startDate, String endDate,String page , String limit,String order,String sort)  {
        return mipsSettlementUploadImpl.find(yblx,patientId,startDate,endDate,page,limit,order,sort);
    }

    @PostMapping(value= "/saveMipsSettleMentUploadDetail")
    public String saveMipsSettleMentUploadDetail(MipsSettlementUpload mipsSettlementUpload)  {
        return mipsSettlementUploadImpl.save(mipsSettlementUpload);
    }

    @PostMapping(value= "/findMedicalRecord")
    public String findMedicalRecord(String patientId)  {
        return hisCaseRecordService.queryRecordByPatientId(patientId);
    }

    @PostMapping(value= "/parseMedicalRecord")
    public String parseMedicalRecord(String id)  {
        return hisCaseRecordService.parseById(Integer.valueOf(id));
    }

    @PostMapping(value= "/parseMedicalRecordText")
    public String parseMedicalRecordText(String id)  {
        return hisCaseRecordService.parseTextById(Integer.valueOf(id));
    }

    @PostMapping(value= "/parseMedicalRecordXml")
    public String parseMedicalRecordXml(String id)  {
        return hisCaseRecordService.parseXmlById(Integer.valueOf(id));
    }

    @PostMapping(value= "/saveMedicalRecordXml")
    public String saveMedicalRecordXml(String docLobId,String xmlText)  {
        return hisCaseRecordService.saveMedicalRecordXml( docLobId, xmlText);
    }

    @PostMapping(value= "/testWebSocket")
    public String test(HttpServletRequest request) {
        request.getSession().getId();
        return logService.testWebSocket(String.valueOf(request.getSession().getId()));
    }

    @PostMapping(value= "/getSessionId")
    public String getSessionId(HttpServletRequest request) {
        String sessionId = String.valueOf(request.getSession().getId());
        ThreadLocalUtil.setSessionId(sessionId);
        return ResultUtil.success(sessionId);
    }
}
